home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / X3MDMO01.ZIP / PLASMA.PAS < prev    next >
Pascal/Delphi Source File  |  1994-12-13  |  5KB  |  271 lines

  1. {
  2.  ████       ████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3.  ▀███▄     ▄███▀  Project: Plasma Effect [PASCAL]
  4.      ▀███▄ ▄███▀    File   : PLASMA.PAS
  5.          ▀█████▀      Version: 1.00        Created: 261194   Modified: 261194
  6.         ▄███▀███▄
  7.     ▄███▀   ▀███▄   Nice plasma effect by X3M Productions.
  8.  ████       ████  If you have any questions, e-mail: srs@alkymi.unit.no
  9.  ████       ████▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  10. }
  11.  
  12. {$X+}
  13. Uses
  14.     Crt;
  15.  
  16. Type
  17.     RGBType = Record
  18.         R,G,B : Byte;
  19.     End;
  20.     PalType = Array[0..255] of RGBType;
  21.  
  22. Var
  23.     TempPal, ToPal     : PalType;                                        { Temp and current palette }
  24.     CosTbl                     : Array [0..255] of byte;         { Cosinus table }
  25.     Pos1, Pos2,
  26.     Pos3, Pos4            : Byte;                                                { Current positions }
  27.  
  28.  
  29. { This gives sets a color it's red, green and blue value }
  30. Procedure SetCol(Col,R,G,B : Byte); Assembler;
  31. Asm
  32.     mov        dx,3c8h
  33.     mov   al,[col]
  34.     out   dx,al
  35.     inc   dx
  36.     mov   al,[r]
  37.     out   dx,al
  38.     mov   al,[g]
  39.     out   dx,al
  40.     mov   al,[b]
  41.     out   dx,al
  42. End;
  43.  
  44. { Sets the entire palette. Very fast! }
  45. Procedure SetPal(Var Palette : PalType); Assembler;
  46. Asm
  47.     push    ds
  48.     lds   si, Palette
  49.     mov   dx, 3c8h
  50.     mov   al, 0
  51.     out   dx, al
  52.     inc   dx
  53.     mov   cx, 768
  54.     rep   outsb
  55.     pop   ds
  56. End;
  57.  
  58. { Converts degrees to radians }
  59. Function Rad(theta : Real) : Real;
  60. Begin
  61.     rad := theta * pi / 180
  62. End;
  63.  
  64. { Initialize colors }
  65. Procedure InitColors;
  66. Var
  67.     i : Byte;
  68. Begin
  69.     For i:=0 to 63 do
  70.     Begin
  71.         TempPal[i].R             := 63;
  72.         TempPal[i].G             := i;
  73.         TempPal[i].B             := 63-i;
  74.         TempPal[i+64].R     := 63-i;
  75.         TempPal[i+64].G     := 63;
  76.         TempPal[i+64].B     := i;
  77.         TempPal[i+128].R     := 0;
  78.         TempPal[i+128].G     := 63-i;
  79.         TempPal[i+128].B     := 63;
  80.         TempPal[i+192].R     := i;
  81.         TempPal[i+192].G     := 0;
  82.         TempPal[i+192].B     := 63;
  83.     End;
  84. End;
  85.  
  86. { Initializes plasma colors and look-up table }
  87. Procedure InitPlasma;
  88. Var
  89.     i : Byte;
  90. Begin
  91.     Asm
  92.         mov        ax,0013h
  93.         int      10h                                     { Enter mode 13 }
  94.         cli
  95.         mov   dx,3c4h
  96.         mov   ax,604h                                 { Enter unchained mode }
  97.         out   dx,ax
  98.         mov   ax,0F02h                                { All planes }
  99.         out   dx,ax
  100.         mov   dx,3D4h
  101.         mov   ax,14h                                        { Disable dword mode}
  102.         out   dx,ax
  103.         mov   ax,0E317h                                 { Enable byte mode.}
  104.         out   dx,ax
  105.         mov   al,9
  106.         out   dx,al
  107.         inc   dx
  108.         in    al,dx
  109.         and   al,0E0h                                       { Duplicate each scan 8 times.}
  110.         add   al,7
  111.         out   dx,al
  112.     End;
  113.  
  114.     FillChar(ToPal,SizeOf(ToPal),0);                  { Clear pallette ToPal }
  115.     SetPal(ToPal);
  116.  
  117.     { Set up cosinus look-up table }
  118.     For i:=0 to 255 do
  119.         CosTbl[i] := Round(Cos(Rad(i/360*255*2))*31)+32;
  120.  
  121.     InitColors;
  122. End;
  123.  
  124. { Draws the plasma on screen }
  125. Procedure DrawPlasma;
  126. Var
  127.     i,j,color,
  128.     tpos1,tpos2,
  129.     tpos3,tpos4     : Byte;
  130.     where                    : Word;
  131. Begin
  132.     tpos3:=pos3;
  133.     tpos4:=pos4;
  134.   where:=0;
  135.  
  136.     Asm
  137.         mov        ax,0a000h
  138.         mov   es,ax
  139.     End;
  140.  
  141.     { 50 rows down }
  142.     For i:=1 to 50 do
  143.     Begin
  144.         tpos1:=pos1;
  145.         tpos2:=pos2;
  146.  
  147.         { 80 columns across }
  148.         For j:=1 to 80 do
  149.         Begin
  150.             { color in the intersection of numerous cos waves }
  151.             color :=     CosTbl[tpos1]+CosTbl[tpos2]+CosTbl[tpos3]+
  152.                                 CosTbl[tpos4]+CosTbl[i]+CosTbl[j];
  153.  
  154.             Asm
  155.                 mov        di,where
  156.                 mov   al,color
  157.                 mov   es:[di],al
  158.             End;
  159.  
  160.             where:=where+1;                              { Inc the place to put the pixel }
  161.             tpos1:=tpos1+4;
  162.             tpos2:=tpos2+3;                                { Try out diffrent combination for
  163.                                                                             different effects }
  164.         End;
  165.         tpos3:=tpos3+4;
  166.         tpos4:=tpos4+5;                                { Try it out here to }
  167.     End;
  168. End;
  169.  
  170. { Moves the plasma left/right/up/down }
  171. Procedure MovePlasma;
  172. Begin
  173.     pos1:=pos1-4;
  174.     pos3:=pos3+4;
  175.     pos1:=pos1+random(1);
  176.     pos2:=pos2-random(2);
  177.     pos3:=pos3+random(1);
  178.     pos4:=pos4-random(2);
  179. End;
  180.  
  181. { Waits for a vertical retrace }
  182. Procedure WaitRetrace; Assembler;
  183. Label
  184.     l1, l2;
  185. Asm
  186.     mov        dx,3DAh
  187. l1:
  188.     in    al,dx
  189.     test  al,8
  190.     jnz   l1
  191. l2:
  192.     in    al,dx
  193.     test  al,8
  194.     jz    l2
  195. End;
  196.  
  197. { Fades up the palette ToPal by incrementing by 1 and sets the onscreen
  198.     palette. }
  199. Procedure FadeUpOne(stage:Integer);
  200. Var
  201.     i     : Byte;
  202.     Tmp : RGBType;
  203. Begin
  204.     Move(TempPal,Tmp,3);
  205.     Move(TempPal[1],TempPal[0],765);
  206.     Move(Tmp,TempPal[255],3);
  207.  
  208.     For i:=0 to 255 do
  209.     Begin
  210.         ToPal[i].R := Integer(TempPal[i].R * stage div 64);
  211.         ToPal[i].G := Integer(TempPal[i].G * stage div 64);
  212.         ToPal[i].B := Integer(TempPal[i].B * stage div 64);
  213.     End;
  214.  
  215.     SetPal(ToPal);
  216. End;
  217.  
  218. { Rotates the palette }
  219. Procedure ShiftPallette;
  220. Var
  221.     Tmp : RGBType;
  222. Begin
  223.     Move(ToPal[0],Tmp,3);
  224.     Move(ToPal[1],ToPal[0],765);
  225.     Move(Tmp,ToPal[255],3);
  226.     SetPal(ToPal);
  227. End;
  228.  
  229. { Main plasma routine }
  230. Procedure DoPlasma;
  231. Var
  232.     i : Byte;
  233. Begin
  234.     { Fades up the plasma }
  235.     For i:=1 to 64 do
  236.     Begin
  237.         FadeUpOne(i);
  238.         DrawPlasma;
  239.         MovePlasma;
  240.     End;
  241.  
  242.     { Do the plasma thing }
  243.     Repeat
  244.         ShiftPallette;
  245.         DrawPlasma;
  246.         MovePlasma;
  247.         {WaitRetrace;} { Use this if you have flicker! }
  248.     Until Keypressed;
  249.  
  250.     { Fades down the plasma }
  251.     Move(ToPal,TempPal,768);
  252.     For i:=1 to 64 do
  253.     Begin
  254.         FadeUpOne(64-i);
  255.         DrawPlasma;
  256.         MovePlasma;
  257.     End;
  258.  
  259.     While keypressed do readkey;
  260.  
  261.     { Back to text mode }
  262.     Asm
  263.         mov  ax,0003h
  264.         int  10h
  265.     End;
  266. End;
  267.  
  268. Begin
  269.     InitPlasma;
  270.     DoPlasma;
  271. End.